<?php
namespace App\Modules\Manage\Http\Controllers;

use App\Http\Controllers\ManageController;
use Illuminate\Http\Request;
use App\Modules\Manage\Model\CategoryModel;
use Session;
use Validator;

class CateController extends ManageController
{

    public function __construct()
    {
        parent::__construct();
        $this->initTheme('manage');
        $this->theme->setTitle('产品分类');
    }

    public function cateList()
    {
        $lists = CategoryModel::cateList();

        return $this->theme->scope('manage.cateList',['lists'=>$lists])->render();
    }

    public function cateInsert(Request $request)
    {
        if ($request->isMethod('post')) {
            $param = $request->except('_token');
            $param['create_time'] = time();
            $param['update_time'] = time();
            $result = CategoryModel::cateInsert($param);
//            var_export($request);
        } else {
            return $this->theme->scope('manage.cateInsert')->render();
        }
    }

    public function cateUpdate(Request $request)
    {
        if ($request->method() == 'POST') {
            $param = $request->except('_token');
            $param['update_time'] = time();
            $result = CategoryModel::cateUpdate($param);
            var_export($result);
            die;
        }

        $id = $request->id;
        $one = CategoryModel::cateOne($id);
        return $this->theme->scope('manage.cateUpdate',['one'=>$one])->render();
    }

}
